Skip to content

Conversation

@burtenshaw
Copy link
Collaborator

This PR adds a guide on structured outputs with inference providers. It uses hf client, openai client, cerebras, qwen3 32b

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@burtenshaw burtenshaw requested a review from stevhliu July 8, 2025 16:36
Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

- local: guides/building-first-app
title: Building Your First AI App
- local: guides/structured-output
title: Structured Outputs with LLMs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would align the toctree title with the doc title (or vice versa) to avoid confusion for users when referencing the doc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the guides be under the provider list?

i think we want to focus on providers more

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(forgot to post this on the previous PR @burtenshaw sorry =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. I'll make another PR with the menu change.

@@ -0,0 +1,467 @@
# Structured Outputs with Inference Providers

In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parseable responses.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parseable responses.
In this guide, we'll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parsable responses.


We'll create a simple schema that captures the most essential elements: the paper's title and a summary of its abstract. The easiest way to do this is to use Pydantic, a library that allows you to define Python classes that represent JSON schemas (among other things).

<hfoptions id="json-pydantic">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use the toggles here since it sets up as a kind of "choose one or the other". After showing the Pydantic code example, maybe transition with:

"The Pydantic represented JSON schema is shown below."


</hfoption>

The OpenAI client returns a `ChatCompletion` object, which contains the response from the model as a Python object. You can then access the structured data using the `title` and `abstract_summary` attributes of the `PaperAnalysis` class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go under the <hfoption id="openai"> toggle

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool doc page, is there one about tool calling coming up as well? :)

Note, @SBrandeis has been building some validation matrix of model/provider support for structured output & function calling, we could dynamically display it here in this page (or link to it from this page)

cc @gary149 too for viz

@burtenshaw
Copy link
Collaborator Author

cool doc page, is there one about tool calling coming up as well? :)

Yep. It's coming tomorrow.

Note, @SBrandeis has been building some validation matrix of model/provider support for structured output & function calling, we could dynamically display it here in this page (or link to it from this page)

👍


## Step 2: Set up your inference client

Now that we have our schema defined, let's set up the client to communicate with the inference providers. We'll show you two approaches: the Hugging Face Hub client (which gives you direct access to all Inference Providers) and the OpenAI client (which works through OpenAI-compatible endpoints).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadge - it's only Python 🥲

Copy link
Collaborator Author

@burtenshaw burtenshaw Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. I'll come back to that on all new guides.

Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very useful !!

@burtenshaw burtenshaw merged commit 96c7427 into main Jul 10, 2025
2 checks passed
@burtenshaw burtenshaw deleted the guide-structured-output branch July 10, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants